/**
 * 首页相关的接口集合
 */
import {request} from "@/utils/http";
import type {CategoryBriefType, ProductItemType} from "@/types/product";
import type {ProductSearchType, RecommendQueryType} from "@/types/home";
import type {PageResultType} from "@/types/global";

/**
 * 获取首页的分类数据
 */
export const getCategoryData = () => {

    return request<Array<CategoryBriefType>>({
        url: "/index/category/top",
        method: "GET"
    })
}
/**
 * 获取首页的推荐数据
 * @param recommendQuery
 */
export const getRecommendData = (recommendQuery: RecommendQueryType) => {
    return request<PageResultType<ProductItemType>>({
        url: "/index/recommend",
        method: "POST",
        data: recommendQuery
    })
}
export const getRecommendCommonData = (recommendQuery: RecommendQueryType) => {
    return request<PageResultType<ProductItemType>>({
        url: "/index/recommend-common",
        method: "POST",
        data: recommendQuery
    })
}
/**
 * 搜索商品接口
 * @param query 关键字
 */
export const searchProductListData = (query: ProductSearchType) => {
    console.log("@search product: ", JSON.stringify(query))
    return request<PageResultType<ProductItemType>>({
        url: "/index/search",
        method: "POST",
        data: query
    })
}